<!DOCTYPE html>
<html>
<head>
    <title>修改运维人员信息</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>
    <script>

        var operatorId = getUrlParam("operatorId");
        var operatorChange = "";
        var operatorMsisdnOrg = "";
        var talkingCodingOrg = "";
        var operatorNameOrg = "";


        function close(status){
            if(status=="yes"){
                window.parent.location.reload();//刷新父页面
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            }
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);
        }

        layui.use(['form', 'jquery', 'layer','element'], function () {
            var operatorId = getUrlParam("operatorId");
            var form = layui.form;
            var $ = layui.$;
            var layer = layui.layer;
            var status = "yes";

            //初始化页面数据
            $(document).ready(function () {
                var url = '/xuYiOperator/findByOperatorId?operatorId=' + operatorId;
                $.ajax({
                    type: 'post',
                    async: false,
                    url: url,
                    success: function (json) {
                        $("#operatorName").val(json.operatorName);
                        $("#operatorMsisdn").val(json.operatorMsisdn);
                        $("#talkingCoding").val(json.talkingCoding);
                        operatorNameOrg=json.operatorName;
                        operatorMsisdnOrg=json.operatorMsisdn;
                        talkingCodingOrg=json.talkingCoding;
                        form.render();
                    }
                })
            });

            $('#modify').on('click', function () {
                var operatorId = getUrlParam("operatorId");
                var url = '/xuYiOperator/configureOperator';
                var operatorName = $.trim($("#operatorName").val());
                var operatorMsisdn = $.trim($("#operatorMsisdn").val());
                var talkingCoding = $.trim($("#talkingCoding").val());
                if (isNull(operatorName)){
                    layer.msg("请输入运维人员名称");
                    $("#operatorName").focus();
                } else if (testMsisdn(operatorMsisdn) || isNull(operatorMsisdn)){
                    layer.msg("请输入合法的手机号码");
                    $("#operatorMsisdn").focus();
                } else if (isNull(talkingCoding)){
                    layer.msg("请输入和对讲编码");
                    $("#talkingCoding").focus();
                } else if (operatorMsisdn == operatorMsisdnOrg && talkingCoding == talkingCodingOrg && operatorName == operatorNameOrg){
                    layer.msg("您未做任何修改，请修改信息");
                } else {
                    if (operatorMsisdn != operatorMsisdnOrg && talkingCoding != talkingCodingOrg){
                        operatorChange=1;  //手机号，和分期编码均修改，名称修改
                    }else if (operatorMsisdn == operatorMsisdnOrg){
                        if (talkingCoding == talkingCodingOrg){
                           operatorChange = 0;   //手机号、和对讲编码均未修改
                        } else {
                           operatorChange = 2;   //手机号未修改,和对讲编码修改
                        }
                    } else if (talkingCoding == talkingCodingOrg){
                           operatorChange = 3;   //核对将编码未修改，手机号改了
                    }
                    var param = {
                       operatorId:operatorId,
                       operatorName:operatorName,
                       operatorMsisdn:operatorMsisdn,
                       talkingCoding:talkingCoding,
                       operatorChange:operatorChange,
                       flag: "modify"
                    };
                    $.ajax({
                       type: 'post',
                       data: param,
                       url: url,
                       success: function (data) {
                           if (data == 1) {
                               layer.confirm('修改成功', {
                                   btn: ['确认'] //按钮
                               }, function () {
                                   close(status);
                               });
                           }else if(data == 2){
                               layer.confirm('手机号及和分期编码均已存在，请更改', {
                                   btn: ['确认'] //按钮
                               });
                           }else if(data == 3){
                               layer.confirm('该手机号已存在，请更改', {
                                   btn: ['确认'] //按钮
                               });
                           }else if(data == 4){
                               layer.confirm('该和分期编码已存在，请更改', {
                                   btn: ['确认'] //按钮
                               });
                           } else {
                               layer.confirm('添加失败，请重试', {
                                   btn: ['确认'] //按钮
                               });
                           }
                       },
                       error: function (data) {
                           layer.msg('系统异常，请联系管理员处理!');
                       }
                    });

               }
            });
            $('#quit').on('click',function(){
                status="no";
                close(status);
            });
        });

    </script>
</head>
<body>
<div class="layui-content-body">
    <div class="scroll-box">
        <div class="content-box">
            <div class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 120px">名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="operatorName" id="operatorName" autocomplete="off" class="layui-input"
                               placeholder="" lay-verify="required" style="width:180px">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 120px">手机号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="operatorMsisdn" id="operatorMsisdn" autocomplete="off" class="layui-input"
                               placeholder="" lay-verify="required" style="width:180px">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 120px">和对讲编码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="talkingCoding" id="talkingCoding" autocomplete="off" class="layui-input"
                               placeholder="" lay-verify="required" style="width:180px">
                    </div>
                </div>

                <div class="layui-block" pane="" style="padding-left:40px;">
                    <button class="layui-btn layui-btn-normal" lay-filter="modify" id="modify" style="min-width: 100px">修改</button>
                    <button class="layui-btn layui-btn-normal" lay-filter="quit" id="quit" style="min-width: 100px">取消</button>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
</html>